﻿tTrawler.UI.search = {
  toggleSearch : function () {
     if(document.getElementById("tTrawler_searchBox").getAttribute("disabled") != "true") {
       document.getElementById("tTrawler_results").disabled = "true";     
       document.getElementById("tTrawler_searchButton").disabled = "true";
       document.getElementById("tTrawler_searchBox").disabled = "true";
       document.getElementById("loading-anim").setAttribute("class", "tTrawler_loading_anim");    
     } else {
       document.getElementById("tTrawler_results").disabled = "";  
       document.getElementById("tTrawler_searchButton").disabled = "";
       document.getElementById("tTrawler_searchBox").disabled = "";
       document.getElementById("loading-anim").setAttribute("class", "tTrawler_loading_static");
     };
  },
  
  buildList : function(results) {
    var results_list = document.getElementById("tTrawler_results");
    for(g in results) {
      var listItem = document.createElement("listitem");
      for (var k=1;k<=4;k++) {
        var tmpObj = document.createElement("listcell");
          switch (k) {
            case 1:case 4:
              tmpObj.setAttribute("class", results[g][k]);
              break;
            default :
              tmpObj.setAttribute("label", results[g][k]);
              break;
          };
       listItem.appendChild(tmpObj);
    }
    results_list.appendChild(listItem);
  }
  },
  
  
  destroyList : function() {
  
    var listItems = [];
    var element = document.getElementById("tTrawler_results");
      for (var child = element.firstChild; child; child = child.nextSibling) {
        if(child.tagName == "listitem") {
          listItems.push(child)
        };
      };
      
      for(i in listItems) {
         element.removeChild(listItems[i]);  
      }
      
     
  } 
}

